﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HalAfstande.Domain;
using HalAfstande.Domain.Objects;

namespace HalAfstande.Web
{
    public partial class WebTool : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void GenerateScheduleClick(object sender, EventArgs eventArgs)
        {
            var referee = new Referee(int.Parse(txbRefNumber.Text), txbName.Text, txbPhone.Text, txbEmail.Text,
                                       txbAddress.Text, txbPostalCode.Text, txbCity.Text);
            var refAddress = string.Format("{0},{1}+{2}", referee.Address, referee.PostalCode, referee.City);

            var halInfo = new DataHandler(refAddress, ConfigurationManager.AppSettings["DataLocation"]);
            domeDistanceSchema.DataSource = halInfo.Haller.Select(x => new { x.Name, x.Address, x.DistanceInKm, x.DistanceInTime }).ToList();
            domeDistanceSchema.AutoGenerateColumns = true;
            domeDistanceSchema.DataBind();

            //progressBar1.Visible = false;
            //label8.Visible = false;
            var filePath = ConfigurationManager.AppSettings["fileSavePath"];
            halInfo.BuildExportFile(referee, string.Format(Server.MapPath(filePath), referee.RefereeNumber));
            scheduleDownloadLink.NavigateUrl = string.Format(filePath, referee.RefereeNumber);
            scheduleDownloadLink.Text = "Download dit skema her";
        }
    }
}